home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / lfs / lfsInt.h < prev    next >
C/C++ Source or Header  |  1991-08-08  |  12KB  |  303 lines

  1. /*
  2.  * lfsInt.h --
  3.  *
  4.  *    Type and data uses internally to the LFS module.
  5.  *
  6.  * Copyright 1989 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  *
  15.  * $Header: /sprite/src/kernel/lfs/RCS/lfsInt.h,v 1.11 91/08/08 17:47:22 mendel Exp $ SPRITE (Berkeley)
  16.  */
  17.  
  18. #ifndef _LFSINT
  19. #define _LFSINT
  20.  
  21. #include <sprite.h>
  22. #include <fs.h>
  23. #include <fsconsist.h>
  24. #include <user/fs.h>
  25. #include <lfs.h>
  26. #include <lfsDesc.h>
  27. #include <lfsDescMapInt.h>
  28. #include <lfsDescInt.h>
  29. #include <lfsSuperBlock.h>
  30. #include <lfsSegUsageInt.h>
  31. #include <lfsFileLayoutInt.h>
  32. #include <lfsDirLogInt.h>
  33. #include <lfsMemInt.h>
  34. #include <lfsStats.h>
  35.  
  36. #include <fsdm.h>
  37.  
  38. /*
  39.  * So we can use printf and bzero, bcopy in the lfs module.
  40.  */
  41. #include <stdio.h> 
  42. #include <bstring.h>
  43.  
  44. /* constants */
  45. /*
  46.  * Flags for checkpoint callback.
  47.  * LFS_CHECKPOINT_DETACH - This checkpoint is part of a file system detach.
  48.  *                       Any data structures malloc'ed for this file
  49.  *                   system during attach should be freed.
  50.  * LFS_CHECKPOINT_NOSEG_WAIT - This checkpoint shouldn't wait for clean
  51.  *                segments because it is a checkpoint after
  52.  *                a cleaning.
  53.  * LFS_CHECKPOINT_WRITEBACK - This checkpoint is being done for a domain
  54.  *                  writeback operation.
  55.  * LFS_CHECKPOINT_TIMER - This checkpoint is part of the regular callback.
  56.  * LFS_CHECKPOINT_CLEANER - This checkpoint is part of the cleaner.
  57.  * 
  58.  */
  59. #define    LFS_CHECKPOINT_DETACH         0x1
  60. #define    LFS_CHECKPOINT_NOSEG_WAIT     0x2
  61. #define    LFS_CHECKPOINT_WRITEBACK     0x4
  62. #define    LFS_CHECKPOINT_TIMER         0x8
  63. #define    LFS_CHECKPOINT_CLEANER         0x10
  64. /* data structures */
  65.  
  66. /*
  67.  * LfsCheckPoint contains the info and memory needed to perform checkpoints.
  68.  * The file system timestamp and the next checkpoint area to write
  69.  * indicator are kept here. 
  70.  */
  71. typedef struct LfsCheckPoint {
  72.     int      timestamp;    /* Current file system timestamp. */
  73.     int      nextArea;    /* Next checkpoint area to write. Must be 0 or 1. */
  74.     char  *buffer;    /* Memory buffer to place checkpoint. */
  75.     int      maxSize;    /* Maximum size of the buffer. */
  76. } LfsCheckPoint;
  77.  
  78. /*
  79.  * LfsSegCache - Data structure describing the in memory cache of segments.  
  80.  * With the current implementation, this cache contains the last segment
  81.  * read during cleaning and it takes any hits during cleaning.
  82.  */
  83. typedef struct LfsSegCache {
  84.     Boolean valid;            /* TRUE if the cache contains valid data. */
  85.     int        segNum;        /* The segment number being cached. */
  86.     LfsDiskAddr  startDiskAddress;  /* The starting and ending disk address */
  87.     LfsDiskAddr  endDiskAddress;    /* of the cached segment.  */
  88.     char    *memPtr;        /* Memory location of segment. */
  89. } LfsSegCache;
  90.  
  91. /*
  92.  * Lfs - The main data structure describing an LFS file system.
  93.  */
  94. typedef struct Lfs {
  95.         /*
  96.          * Fields that are set at attach time and then read-only
  97.          * until detach.
  98.          */
  99.     Fs_Device      *devicePtr;    /* Device containing file system. */
  100.     char      *name;    /* Name used for error messages. */
  101.     int          controlFlags;    /* Flags controlling file system operating. 
  102.                  * see lfs.h for definitions.  */
  103.     Fsdm_Domain      *domainPtr;    /* Domain this file system belongs. */
  104.     /*
  105.      * Routine for cache backend. 
  106.      */
  107.     Sync_Lock      cacheBackendLock; /* Lock for cache backend use. */
  108.     Boolean       writeBackActive; /* TRUE if cache backend is active. */
  109.     Boolean        writeBackMoreWork; /* TRUE if more work is available for
  110.                        * the cache backend. */
  111.     Boolean       shutDownActive;   /* TRUE if the file system is being 
  112.                       * shutdown. */
  113.     int          cacheBlocksReserved; /* Number of file cache blocks
  114.                     * reserved for file system. */
  115.     int             attachFlags;    /* Flags from Lfs_AttachDisk() call.  */
  116.     int                blockSizeShift;   /* Log base 2 of blockSize. Used by
  117.                      * Blocks<->Bytes macros below to 
  118.                      * use fast shifts rather than costly 
  119.                      * multiplies and divides. */
  120.     int    *checkpointIntervalPtr; /* A pointer to the interval to call
  121.                 * the checkpoint processor on. A 
  122.                 * value of zero will cause the 
  123.                 * checkpoint process to stop. */
  124.         /*
  125.          * Fields modified after boot that require locking.
  126.          */
  127.     Sync_Lock      lock;    /* Lock protecting the below data structures. */
  128.     int        activeFlags;    /* Flags specifing what processes are active
  129.                  * on file system. See below for values. */
  130.     Proc_ControlBlock *cleanerProcPtr; /* Process Control block of cleaner
  131.                     * process. NIL if cleaner is not
  132.                     * active. */
  133.     Sync_Condition writeWait; /* Condition to wait for the file system 
  134.                    * write to complete. */
  135.     Sync_Condition cleanSegmentsWait; /* Condition to wait for clean
  136.                        * segments to be generated. */
  137.     Sync_Condition checkPointWait; /* Condition to wait for checkpoint
  138.                     * completing or starting. */
  139.     int        dirModsActive;    /* Number of processes inside directory 
  140.                  * modification code. */
  141.     int        numDirtyBlocks; /* Estimate of the number of dirty blocks
  142.                  * in the file cache. */
  143.     LfsSegCache   segCache;      /* Cache of recently read segments. */
  144.     LfsDescCache  descCache;      /* Cache of file desciptors. */
  145.     Sync_Lock     logLock;    /* Lock protecting the directory log. */
  146.     LfsDirLog      dirLog;     /* Directory change log data structures. */
  147.     Boolean      segMemInUse;    /* TRUE if segment memory is being used. */
  148.     LfsDescMap      descMap;    /* Descriptor map data. */
  149.     LfsSegUsage   usageArray;   /* Segment usage array data. */
  150.     Sync_Lock     checkPointLock; /* Lock protecting the checkpoint data. */
  151.     LfsCheckPoint checkPoint;   /* Checkpoint data. */
  152.     LfsFileLayout fileLayout;    /* File layout data structures. */
  153.     LfsSuperBlock superBlock;    /* Copy of the file system's super block 
  154.                  * read at attach time. */
  155.     Lfs_Stats    stats;        /* Stats on the file system.  */
  156.     /*
  157.      * Segment data structures. Currently three segments are 
  158.      * preallocated: one for writing, one for cleaning, and one for the
  159.      * checkpoint processes.
  160.      */
  161. #define    LFS_NUM_PREALLOC_SEGS    3
  162.     int        segsInUse;
  163.     struct LfsSeg *segs;
  164.     char   *writeBuffers[2];    /* Buffers used to speed segment writes. */
  165.     LfsMem    mem;        /* Memory resources allocated to file system. */
  166. } Lfs;
  167.  
  168. /*
  169.  * Possible values for activeFlags:
  170.  * LFS_CLEANER_ACTIVE      - A segment cleaner process is active on this file 
  171.  *                system.
  172.  * LFS_WRITE_ACTIVE      - Someone is actively writing to the log.
  173.  * LFS_CHECKPOINT_ACTIVE  - A checkpoint is active on this file system.
  174.  * LFS_SHUTDOWN_ACTIVE    - The file system is about to be shutdown.
  175.  * LFS_CHECKPOINTWAIT_ACTIVE - Someone is waiting for a checkpoint to be
  176.  *                   performed.
  177.  * LFS_CLEANER_CHECKPOINT_ACTIVE - A segment cleaner is doing a checkpoint.
  178.  * LFS_SYNC_CHECKPOINT_ACTIVE - A segment cleaner is doing a checkpoint.
  179.  * LFS_CLEANSEGWAIT_ACTIVE - Someone is waiting for clean segments to be
  180.  *                 generated.
  181.  */
  182.  
  183. #define    LFS_WRITE_ACTIVE      0x1
  184. #define    LFS_CLEANER_ACTIVE     0x10
  185. #define    LFS_SHUTDOWN_ACTIVE     0x40
  186. #define    LFS_CHECKPOINTWAIT_ACTIVE 0x80
  187. #define    LFS_SYNC_CHECKPOINT_ACTIVE 0x100
  188. #define    LFS_CLEANER_CHECKPOINT_ACTIVE 0x200
  189. #define    LFS_CHECKPOINT_ACTIVE 0x300
  190. #define    LFS_CLEANSEGWAIT_ACTIVE    0x400
  191.  
  192. extern int lfsMinNumberToClean;
  193.  
  194. /* Useful macros for LFS.
  195.  *
  196.  * LfsFromDomainPtr(domainPtr) - Return the Lfs data stucture for a Fsdm_domain.
  197.  *
  198.  * LfsSegSize(lfsPtr)    - Return the segment size in bytes.
  199.  * LfsSegSizeInBlocks(lfsPtr) - Return the segment size in blocks.
  200.  * LfsBlockSize(lfsPtr)       - Return the block size.
  201.  * LfsBytesToBlocks(lfsPtr, bytes) - Convert bytes into the number of blocks
  202.  *                     it would take to contain the bytes.
  203.  * LfsBlocksToBytes(lfsPtr, blocks) - Convert from blocks into bytes.
  204.  * LfsSegNumToDiskAddress(lfsPtr, segNum) - Convert a segment number into
  205.  *                        a disk address.
  206.  * LfsBlockToSegmentNum(lfsPtr, diskAdress)  - Compute the segment number 
  207.  *                     of a disk  address .
  208.  * LfsIsCleanerProcess(lfsPtr) - Return TRUE if current process is a cleaner.
  209.  *
  210.  * LfsGetCurrentTimestamp(lfsPtr) - Return the current file system timestamp
  211.  */
  212.  
  213. #define    LfsFromDomainPtr(domainPtr) ((Lfs *) ((domainPtr)->clientData))
  214.  
  215. #define    LfsSegSize(lfsPtr) ((lfsPtr)->usageArray.params.segmentSize)
  216.  
  217. #define    LfsSegSizeInBlocks(lfsPtr) \
  218.             (LfsSegSize(lfsPtr)>>(lfsPtr)->blockSizeShift)
  219.  
  220. #define    LfsBlockSize(lfsPtr) ((lfsPtr)->superBlock.hdr.blockSize)
  221.  
  222. #define    LfsBytesToBlocks(lfsPtr, bytes)    \
  223.      (((bytes) + (LfsBlockSize(lfsPtr)-1))>>(lfsPtr)->blockSizeShift)
  224.  
  225. #define    LfsBlocksToBytes(lfsPtr, blocks) ((blocks)<<(lfsPtr)->blockSizeShift)
  226.  
  227.  
  228. #define LfsValidSegmentNum(lfsPtr, segNum) (((segNum) >= 0) && \
  229.         ((segNum) < (lfsPtr)->usageArray.params.numberSegments))
  230.  
  231.  
  232. #define LfsSegNumToDiskAddress(lfsPtr, segNum, diskAddrPtr) \
  233.         LfsOffsetToDiskAddr(  \
  234.              ((lfsPtr)->superBlock.hdr.logStartOffset + \
  235.         (LfsSegSizeInBlocks((lfsPtr)) * (segNum))), diskAddrPtr)
  236.  
  237. #define LfsDiskAddrToSegmentNum(lfsPtr, diskAddress) \
  238.         ((LfsDiskAddrToOffset(diskAddress) - \
  239.                 (lfsPtr)->superBlock.hdr.logStartOffset) / \
  240.                      LfsSegSizeInBlocks((lfsPtr)))
  241.  
  242. #define    LfsGetCurrentTimestamp(lfsPtr)    (++((lfsPtr)->checkPoint.timestamp))
  243.  
  244. #define    LfsIsCleanerProcess(lfsPtr) \
  245.         (Proc_GetCurrentProc() == (lfsPtr)->cleanerProcPtr)
  246.  
  247. /*
  248.  * Attach detach routines. 
  249.  */
  250. extern ReturnStatus LfsLoadFileSystem _ARGS_((Lfs *lfsPtr, int flags));
  251. extern ReturnStatus LfsDetachFileSystem _ARGS_((Lfs *lfsPtr));
  252. extern ReturnStatus LfsCheckPointFileSystem _ARGS_((Lfs *lfsPtr, int flags));
  253.  
  254.  
  255.  
  256. /*
  257.  * Utility  routines.
  258.  */
  259. extern int LfsLogBase2 _ARGS_((unsigned int val));
  260. extern void LfsError _ARGS_((Lfs *lfsPtr, ReturnStatus status, char *message));
  261. extern void LfsSegCleanStart _ARGS_((Lfs *lfsPtr));
  262. extern void LfsWaitForCheckPoint _ARGS_((Lfs *lfsPtr));
  263. extern void LfsSegmentWriteProc _ARGS_((ClientData clientData,
  264.                 Proc_CallInfo *callInfoPtr));
  265. extern void LfsWaitForCleanSegments _ARGS_((Lfs *lfsPtr));
  266.  
  267. extern void Lfs_ReallocBlock _ARGS_((ClientData data, 
  268.                 Proc_CallInfo *callInfoPtr));
  269. extern Boolean Lfs_StartWriteBack _ARGS_((Fscache_Backend *backendPtr));
  270. extern void LfsStopWriteBack _ARGS_((Lfs *lfsPtr));
  271. extern Boolean LfsMoreToWriteBack _ARGS_((Lfs *lfsPtr));
  272. extern Fscache_Backend *LfsCacheBackendInit _ARGS_((Lfs *lfsPtr));
  273. /*
  274.  * I/o routines. 
  275.  */
  276. extern ReturnStatus LfsReadBytes _ARGS_((Lfs *lfsPtr, LfsDiskAddr diskAddress, 
  277.             int numBytes, char *bufferPtr));
  278. extern ReturnStatus LfsWriteBytes _ARGS_((Lfs *lfsPtr, LfsDiskAddr diskAddress, 
  279.             int numBytes, char *bufferPtr));
  280. extern void LfsCheckRead _ARGS_((Lfs *lfsPtr, LfsDiskAddr diskAddress, 
  281.                 int numBytes));
  282.  
  283. /*
  284.  * File index routines. 
  285.  */
  286. extern ReturnStatus LfsFile_GetIndex _ARGS_((Fsio_FileIOHandle *handlePtr,
  287.             int blockNum, int cacheFlags, 
  288.             LfsDiskAddr *diskAddressPtr));
  289. extern ReturnStatus LfsFile_SetIndex _ARGS_((Fsio_FileIOHandle *handlePtr, 
  290.             int blockNum, int blockSize, int cacheFlags, 
  291.             LfsDiskAddr diskAddress));
  292.  
  293. extern ReturnStatus LfsFile_TruncIndex _ARGS_((struct Lfs *lfsPtr, 
  294.             Fsio_FileIOHandle *handlePtr, 
  295.             int length));
  296.  
  297. extern ReturnStatus LfsFile_GrowBlock _ARGS_((Lfs *lfsPtr, 
  298.             Fsio_FileIOHandle *handlePtr,
  299.             int offset, int numBytes));
  300.  
  301. #endif /* _LFSINT */
  302.  
  303.